export default function(){
    function dataManipulation(){

    }
    $.extend(dataManipulation.prototype,{
        init : function(){
            this.cart_detail = $(".cart-detail-list");
            this.total_price = $(".goods-total-price");//总价
            $(this.cart_detail).on( "click" , ".left-down" ,$.proxy(this.reduceGoodsNum,this));
            $(this.cart_detail ).on("click" , ".right-up"  ,$.proxy(this.addGoodsNum,this));
            $(this.cart_detail).on( "click" , ".del-btn" , $.proxy(this.delete,this));
        },
        reduceGoodsNum : function(evt){
            var e = evt || window.event;
            var target = e.target || e.srcElement;
            var id = $(target).parent().attr("data-id");
            this.middle_content = $(target).siblings(".middle-content_1");
            var la = JSON.parse(localStorage.getItem("goods"));
            $.each(la,$.proxy(function(index,item){
                  if(item.id == id){
                        item.count --;
                        if(item.count === 0){
                            la.splice(index,1);
                        }
                        $(this.middle_content).html(item.count);
                    }
            },this))
            localStorage.setItem("goods" , JSON.stringify(la));
            setTimeout(function(){
                location.reload(true); 
            },200)
        },
        addGoodsNum : function(evt){
            var e = evt || window.event;
            var target = e.target || e.srcElement;
            var id = $(target).parent().attr("data-id");
            this.middle_content = $(target).siblings(".middle-content_1");
            var la = JSON.parse(localStorage.getItem("goods"));
            $.each(la,$.proxy(function(index,item){
                if(item.id == id){
                    item.count ++;
                    $(this.middle_content).html(item.count);
                }
            },this))
            localStorage.setItem("goods" , JSON.stringify(la));
            setTimeout(function(){
                location.reload(true); 
            },200)
        },
        delete : function(evt){
            var e = evt || window.event;
            var target = e.target || e.srcElement;
            var id = $(target).parent().attr("data-id");
            var la = JSON.parse(localStorage.getItem("goods"));
            la.forEach( function(item,index){
                if(item.id == id){
                    la.splice(index,1);
                }
            })
            localStorage.setItem("goods",JSON.stringify(la));
            location.reload(true);
        }
    })
    return new dataManipulation();
}